package com.loan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.loan.entity.Customer;
import com.loan.entity.User;
import com.loan.exception.CustomerException;
import com.loan.mappers.CustomerMapper;
import com.loan.mappers.UserMapper;
import com.loan.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
    @Autowired
    CustomerMapper customerMapper;
    @Autowired
    UserMapper userMapper;

    @Override
    @Transactional
    public void addCustomer(Customer customer) {
      customerMapper.insert(customer);
    }

    @Override
    public List<Customer> listByCondition(Customer customer) {
        return customerMapper.findByCondition(customer);
    }

    /**
     * 删除，修改状态
     * @param
     */
    @Override
    public void del(Customer customer){
        customer.setDel("y");
        customerMapper.update(customer);
    }

    /**
     * 修改
     * @param
     */
    @Override
    public void update(Customer customer) {

        customerMapper.update(customer);
        }

    @Override
    public PageInfo<Customer> findByCondition(int pageNum,Customer customer) {
        PageHelper.startPage(pageNum,2);
        List<Customer>customers=customerMapper.findByCondition(customer);
        return new PageInfo<>(customers);
    }

    @Override
    public PageInfo<User> listNoEmp(int pageNum) {
        List<User>users=userMapper.listNoEmp();
        return new PageInfo<>(users);
    }

    @Override
    public PageInfo<Customer> listAll(int empId,int pageNum) {
        Customer customer=new Customer();
        customer.setEmpId(empId);
        List<Customer>customers=customerMapper.findByCondition(customer);
        return new PageInfo<>(customers);
    }


}
